package com.shinewind.search.config.resthignlevelclient.config;

import com.shinewind.search.config.resthignlevelclient.properties.RestHignLevelClientProperties;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(RestHignLevelClientProperties.class)
@ConditionalOnProperty(value = "es.enable",havingValue = "true")
public class RestHignLevelClientConfiguration {
    @Autowired
    private RestHignLevelClientProperties restHignLevelClientProperties;

    @Bean
    public RestHighLevelClient getRestHignLevelClient(){
        System.out.println("restHignLevelClientProperties"+restHignLevelClientProperties);
        return new RestHighLevelClient(RestClient.builder(HttpHost.create(restHignLevelClientProperties.getHttpHost())));
    }
}